$(document).ready(function () {
     checkSports();

    $("#c1").change(function(){
       checkSports();
    });
    function checkSports() {
        if($("#c1").val()==1){
            $("#d2").hide();

        }else{
            $("#d1").hide();
            $("#d2").show();
        }
    }

    $("#q1").click(function () {
        var type = $("#c1").val();
        var userId = $("#i1").val();
        $("#c1").attr("disabled","disabled").css("background-color","#EEEEEE;");
        $.ajax({
            type: "GET",
            url: "/sport/checkType",
            dataType: "text",
            data: {
                type: type,
                userId : userId,
            },
            success: function (data) {
                console.log(data);
                if ("exist"==data) {
                    alert("已选择!!")
                }
                else {
                    alert("添加成功");
                }
                $("#t1").hide();
                $("#q1").hide();
                $("#start").show();

            },
            error: function (xhr, textStatus) {
                console.log('错误');
                console.log(xhr);
                console.log(textStatus);
            }
        });
    })
        $.ajax({
            type: "GET",
            url: "/dpost/getUserId",
            dataType: "json",
            success: function (data) {
                console.log(data);
             $("#i1").val(data);
                $.ajax({
                    type: "GET",
                    url: "/sport/checkSport",
                    dataType: "text",
                    data: {
                        userId : $("#i1").val(),
                    },
                    success: function (data) {
                        console.log(data);
                        if ("run"==data) {
                            alert("已选择环湖跑!!");
                            $("#c1").attr("disabled","disabled").css("background-color","#EEEEEE;");
                            $("#q1").attr("disabled","disabled").css("background-color","#EEEEEE;");
                        }
                        else if("shinei"==data){
                            alert("已选择室内运动!!");
                            $("#d1").hide();
                            $("#d2").show();
                            $("#c1").val(0);
                            $("#c1").attr("disabled","disabled").css("background-color","#EEEEEE;");
                            $("#q1").attr("disabled","disabled").css("background-color","#EEEEEE;");
                        }
                        else{
                            alert("选择运动方式！");
                        }
                    },
                    error: function (xhr, textStatus) {
                        console.log('错误');
                        console.log(xhr);
                        console.log(textStatus);
                    }
                });
            },
            error: function (xhr, textStatus) {
                console.log('错误');
                console.log(xhr);
                console.log(textStatus);
            }
        });
    $.ajax({
        type: "GET",
        url: "/dpost/getLocation",
        dataType: "json",
        success: function (data) {
            console.log(data);
            for (var i in data) {
                $("#ta1").append("<tr><td>" + data[i].x+ "</td><td>" + data[i].y + "</td></tr>");
            }
        },
        error: function (xhr, textStatus) {
            console.log('错误');
            console.log(xhr);
            console.log(textStatus);
        }
    });
})